import API from "API";
import {request as Request} from "Ajax";
import CustomError from "../utils/CustomError";
module.exports = {

    /*
    * 获取短信验证码
    * */
    getSms: async function (data = {}) {
        try {
            return await Request({
                url: API.sms,
                method: "POST",
                data
            })
        } catch (e) {
            throw new CustomError (e, "User.getSms").parse()
        }
    },

    /*
    * 登录
    * */
    login: async function (url = API.login, data = {}) {
        try {
            let res = await Request({
                url: url,
                method: "POST",
                data
            })
            const app = getApp();
            app.globalData.isRedirectToLoginPage = false;
            return res
        } catch (e) {
            throw new CustomError (e, "User.login").parse()
        }
    },

    /*
    * 注册
    * */
    register: async function (data = {}) {
        try {
            return await Request({
                url: API.register,
                method: "POST",
                data
            })
        } catch (e) {
            throw new CustomError (e, "User.register").parse()
        }
    },

    /*
    * 修改密码
    * */
    revisePassword: async function (data = {}) {
        try {
            return await Request({
                url: API.revisePassword,
                method: "POST",
                data
            })
        } catch (e) {
            throw new CustomError (e, "User.revisePassword").parse()
        }
    },

    /*
    * 获取登录人信息
    * */
    getInfo: async function (data = {}) {
        try {
            return await Request({
                url: API.userInfo,
                data
            })
        } catch (e) {
            throw new CustomError (e, "User.getInfo").parse()
        }
    },

    /*
    * 个人资产
    * */
    getAssets: async function () {
        try {
            return await Request({
                url: API.userAssets
            })
        } catch (e) {
            throw new CustomError (e, "User.getAssets").parse()
        }
    },

    /*
    * 我的持仓
    * */
    getPositions: async function (data = {}) {
        try {
            return await Request({
                url: API.userPosition,
                data
            })
        } catch (e) {
            throw new CustomError (e, "User.getPositions").parse()
        }
    },

    /*
    * 分红明细
    * */
    getDividends: async function (data = {}) {
        try {
            return await Request({
                url: API.userDividend,
                data
            })
        } catch (e) {
            throw new CustomError (e, "User.getDividends").parse()
        }
    },

    /*
    * 申赎明细
    * */
    getChanges: async function (data = {}) {
        try {
            return await Request({
                url: API.userChange,
                data
            })
        } catch (e) {
            throw new CustomError (e, "User.getChanges").parse()
        }
    },

    /*信息披露*/
    getDisclosures: async function () {
        try {
            return await Request({
                url: API.userDisclosure
            })
        } catch (e) {
            throw new CustomError (e, "User.getDisclosures").parse()
        }
    }
}